package com.tianlan.blog.controller;


import java.util.List;

import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.tianlan.blog.dto.LogInfo;
import com.tianlan.blog.dto.QueryLog;
import com.tianlan.blog.service.SysLogService;
import com.tianlan.common.base.EntityUtils;
import com.tianlan.common.base.PageResult;
import com.tianlan.common.page.MyPage;

import io.swagger.annotations.ApiOperation;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tl-wxq
 * @since
 */
@RestController
@RequestMapping("/common/log")
public class LogController {
    
    @Autowired
    private SysLogService logService;

    @GetMapping("/list")
    @RequiresRoles("SYSADMIN")
    @ApiOperation(value = "查询操作日志列表")
    public PageResult<LogInfo> list(QueryLog log, MyPage<LogInfo> page) {
    	List<Object[]> LogObj = logService.queryLogList(log,page);
    	LogInfo logEntity = new LogInfo();
    	List<LogInfo> logView = EntityUtils.castEntity(LogObj, LogInfo.class,logEntity);
    	page.setRecords(logView);
    	page.setTotal(logService.queryLogCount(log));    	
        PageResult<LogInfo> pageResult = new PageResult<LogInfo>(page.getTotal(), page.getRecords());
        return pageResult;
    }
	
}
